package com.hedgehoglab.fixxclipse.preferences;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

public class Preferences extends PreferencePage implements
		IWorkbenchPreferencePage {

	private static final String SERVER = "one.server";
	private static final String PORT = "one.port";
	private static final String RETURNAS = "one.returnAs";
	
	 private Text fieldOne;
	  private Text fieldTwo;
	  private Text fieldThree;
	  
	public Preferences() {
		// TODO Auto-generated constructor stub
	}

	public Preferences(String title) {
		super(title);
		// TODO Auto-generated constructor stub
	}

	public Preferences(String title, ImageDescriptor image) {
		super(title, image);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected Control createContents(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
	    composite.setLayout(new GridLayout(2, false));
	    
	    IPreferenceStore preferenceStore = getPreferenceStore();
	    
	    new Label(composite, SWT.LEFT).setText("Server:");
	    Text fieldOne = new Text(composite, SWT.BORDER);
	    fieldOne.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	    fieldOne.setText(preferenceStore.getString(SERVER));

	    return composite;
	}

	public void init(IWorkbench workbench) {
		// TODO Auto-generated method stub

	}
	
	protected void performDefaults() {
	    // Get the preference store
	    IPreferenceStore preferenceStore = getPreferenceStore();
		// Reset the fields to the defaults
	    fieldOne.setText(preferenceStore.getDefaultString(SERVER));
	  }
	
	public boolean performOk() {
	    // Get the preference store
	    IPreferenceStore preferenceStore = getPreferenceStore();

	    // Set the values from the fields
	    if (fieldOne != null) preferenceStore.setValue(SERVER, fieldOne.getText());
	    // Return true to allow dialog to close
	    return true;
	}
}
